home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WINER.ZIP / CHAP6-7.BAS < prev    next >
BASIC Source File  |  1992-05-13  |  2KB  |  80 lines

  1. '*********** CHAP6-7.BAS - shows how to load/save huge arrays
  2.  
  3. 'Copyright (c) 1992 Ethan Winer
  4.  
  5. DEFINT A-Z
  6. 'NOTE: This program must be compiled with the /ah option.
  7.  
  8. DECLARE SUB BigLoad (FileName$, Segment, Address, NumBytes&)
  9. DECLARE SUB BigSave (FileName$, Segment, Address, NumBytes&)
  10. DECLARE SUB BCGet ALIAS "B$Get3" (BYVAL FileNum, BYVAL Segment, BYVAL Address, BYVAL NumBytes)
  11. DECLARE SUB BCPut ALIAS "B$Put3" (BYVAL FileNum, BYVAL Segment, BYVAL Address, BYVAL NumBytes)
  12.  
  13. CONST NumEls% = 20000
  14. REDIM Array&(1 TO NumEls%)
  15. NumBytes& = LEN(Array&(1)) * CLNG(NumEls%)
  16.  
  17. FOR X = 1 TO NumEls%            'fill the array
  18.   Array&(X) = X
  19. NEXT
  20.  
  21. Segment = VARSEG(Array&(1))     'save the array
  22. Address = VARPTR(Array&(1))
  23. CALL BigSave("ARRAY.DAT", Segment, Address, NumBytes&)
  24.  
  25. REDIM Array&(1 TO NumEls%)      'clear the array
  26.  
  27. Segment = VARSEG(Array&(1))     'reload the array
  28. Address = VARPTR(Array&(1))
  29. CALL BigLoad("ARRAY.DAT", Segment, Address, NumBytes&)
  30.  
  31. FOR X = 1 TO NumEls%            'prove this all worked
  32.   IF Array&(X) <> X THEN
  33.     PRINT "Error in element"; X
  34.   END IF
  35. NEXT
  36.  
  37. SUB BigLoad (FileName$, DataSeg, Address, Bytes&) STATIC
  38.  
  39.   FileNum = FREEFILE
  40.   OPEN FileName$ FOR BINARY AS #FileNum
  41.   NumBytes& = Bytes&            'work with copies to
  42.   Segment = DataSeg             'protect the parameters
  43.  
  44.   DO
  45.     IF NumBytes& > 16384 THEN
  46.       CurrentBytes = 16384
  47.     ELSE
  48.       CurrentBytes = NumBytes&
  49.     END IF
  50.     CALL BCGet(FileNum, Segment, Address, CurrentBytes)
  51.     NumBytes& = NumBytes& - CurrentBytes
  52.     Segment = Segment + &H400
  53.   LOOP WHILE NumBytes&
  54.  
  55.   CLOSE #FileNum
  56.   
  57. END SUB
  58.  
  59. SUB BigSave (FileName$, DataSeg, Address, Bytes&) STATIC
  60.  
  61.   FileNum = FREEFILE
  62.   OPEN FileName$ FOR BINARY AS #FileNum
  63.   NumBytes& = Bytes&            'work with copies to
  64.   Segment = DataSeg             'protect the parameters
  65.  
  66.   DO
  67.     IF NumBytes& > 16384 THEN
  68.       CurrentBytes = 16384
  69.     ELSE
  70.       CurrentBytes = NumBytes&
  71.     END IF
  72.     CALL BCPut(FileNum, Segment, Address, CurrentBytes)
  73.     NumBytes& = NumBytes& - CurrentBytes
  74.     Segment = Segment + 1024
  75.   LOOP WHILE NumBytes&
  76.  
  77.   CLOSE #FileNum
  78.  
  79. END SUB
  80.